package com.fs.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fs.mapper.SupMapper;
import com.fs.pojo.Sup;
import com.fs.service.SupService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * @author hyy
 * @version 1.0
 * @description: 供应商接口实现
 * @date 2024/10/14 16:19
 */
@Service
public class SupServiceImpl implements SupService {
    @Resource
    private SupMapper supMapper;


    @Override
    public Integer addSup(Sup sup) {
        return supMapper.insert(sup);
    }

    @Override
    public Integer delSUp(Integer supId) {
        return supMapper.deleteById(supId);
    }

    @Override
    public Integer updateSup(Sup sup) {
        return supMapper.updateById(sup);
    }

    @Override
    public Sup querySupByID(Integer supId) {
        return supMapper.selectById(supId);
    }

    @Override
    public Page<Sup> querySups(Integer pageNum, Integer pageSize, Sup sup) {
        Page<Sup> page = new Page<>(pageNum,pageSize);
        //构建条件构造器
        LambdaQueryWrapper<Sup> wrapper = new LambdaQueryWrapper<Sup>();
        if (Objects.nonNull(sup)){
            //供应商姓名模糊查询条件
            wrapper.like(sup.getSupName()!=null,Sup::getSupName,sup.getSupName())
                    //编号查询
                    .eq(sup.getSupId()!=null,Sup::getSupId,sup.getSupId())
                    //类别
                    .eq(sup.getSupType()!=null,Sup::getSupType,sup.getSupType())
                    //状态
                    .eq(sup.getSupState()!=null,Sup::getSupState,sup.getSupState());
        }
        return supMapper.selectPage(page,wrapper);

    }
}
